package com.example.springpethospital.mapper;

import com.example.springpethospital.entity.*;
import org.apache.ibatis.annotations.*;

import java.util.*;

@Mapper
public interface UserMapper {
    @Select("select id from t_user where username=#{username} and password=#{password}")
    Integer GetIDwithUsernameAndPassword(String username, String password);

    @Insert("insert into t_user(username, password, usertype) values (#{username}, #{password}, #{usertype})")
    void registerUser(String username, String password, int usertype);

    @Select("select id from t_user where username=#{username}")
    Integer getIdwithUsername(String username);

    @Update("update t_user set username=#{username} where id=#{id}")
    boolean setUsername(int id, String username);

    @Update("update t_user set password=#{newPassword} where id=#{id} and password=#{oldPassword}")
    boolean setPassword(int id, String oldPassword, String newPassword);

    @Select("select usertype from t_user where id=#{id}")
    Integer getUserType(int id);

    @Update("update t_user set usertype=#{usertype} where id=#{id}")
    boolean setUserType(int id, int usertype);

    @Select("select id, username, usertype from t_user where username like '%${username}%'")
    List<UserDTO> searchUser(String username);

    @Select("select id, username, usertype from t_user where username like '%${username}%' limit #{offset},#{limit}")
    List<UserDTO> searchUserWithPage(String username, int offset, int limit);

    @Select("select count(*) from t_user where username like '%${username}%'")
    Integer getUserNum(String username);

    @Delete("delete from t_user where id=#{id}")
    boolean removeUser(int id);
}